package com.sevent;

/*
给定整数序列a1,a2,...,an,判断是否可以从中选出若干数,使它们的和恰好为k.

    1≤n≤20

    -10^8≤ai≤10^8

    -10^8≤k≤10^8

样例:

输入

    n=4
    a={1,2,4,7}
    k=13
输出:

    Yes (13 = 2 + 4 + 7)

*/

import java.util.ArrayList;
import java.util.Scanner;

public class dfs题目2_部分和 {
    public static int count = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];

        sc.nextLine();
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        sc.nextLine();
        int k = sc.nextInt();

        dfs(arr, k, 0, new ArrayList<Integer>());
    }

    private static void dfs(int[] arr, int k, int cur, ArrayList<Integer> ints) {
        if (k == 0) {
            count++;
            System.out.println(ints);
        }
        if (cur >= 4) {
            return;
        }
        if (k < 0) {
            return;
        }

        ints.add(arr[cur]);
        int index = ints.size() - 1;
        dfs(arr, k - arr[cur], cur + 1,ints); // 选
        ints.remove(index);
        dfs(arr, k, cur + 1,ints);
    }
}
